package com.gaox.aptcomponenttest;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.gaox.arouter.annotation.ARouter;
import com.gaox.arouter.api.RouterManager;

@ARouter(path = "/app/MainActivity")
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void jumpOrder(View view) {
        RouterManager.getInstance()
                .build("/order/OrderActivity")
                .withString("username", "gaox")
                .navigation(this,100);//加code 说明是startActivityForResult


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            Log.e("gaox>>>>>>>>>",
                    data.getStringExtra("call")
                            +",resultCode:"+requestCode
                            + ",resultCode:"+resultCode);
            //2020-01-10 16:08:05.059 31257-31257/com.gaox.aptcomponenttest E/gaox>>>>>>>>>:
            // I'am comeback!,resultCode:100,resultCode:-1
        }
    }

    public void jumpPersonal(View view) {
        RouterManager.getInstance()
                .build("/personal/PersonalActivity")
                .withString("password", "222222")
                .navigation(this);
    }


    //    public void jumpOrder(View view) {
    //
    ////         最终集成化模式，所有子模块app/order/personal通过APT生成的类文件都会打包到apk里面，不用担心找不到
    //        ARouterLoadGroup group = new ARouter$$Group$$order();
    //        Map<String, Class<? extends ARouterLoadPath>> map = group.loadGroup();
    //        // 通过order组名获取对应路由路径对象
    //        Class<? extends ARouterLoadPath> clazz = map.get("order");
    //
    //        try {
    //            // 类加载动态加载路由路径对象
    //            ARouter$$Path$$order path = (ARouter$$Path$$order) clazz.newInstance();
    //            Map<String, RouterBean> pathMap = path.loadPath();
    //            // 获取目标对象封装
    //            RouterBean bean = pathMap.get("/order/OrderActivity");
    //
    //            if (bean != null) {
    //                Intent intent = new Intent(this, bean.getClazz());
    //                intent.putExtra("name", "simon");
    //                startActivity(intent);
    //            }
    //        } catch (Exception e) {
    //            e.printStackTrace();
    //        }
    //    }
    //
    //    public void jumpPersonal(View view) {
    //        Intent intent = new Intent(this, PersonalActivity.class);
    //        intent.putExtra("name", "simon");
    //        startActivity(intent);
    //    }
}
